﻿@using NewLife;
@using NewLife.Cube
@using XCode
@{
    var entity = Model as IEntity;
    var set = ViewBag.PageSetting as PageSetting ?? PageSetting.Global;

    var rv = entity.GetRouteKey();
}
@if (set.IsReadOnly)
{
    if (this.Has(PermissionFlags.Detail))
    {
        @*<i class="glyphicon glyphicon-edit" style="color: blue;"></i>*@
        <a href="@Url.Action("Detail", rv)" class="btn btn-primary btn-xs editcell">查看</a>
    }
}
else if (this.Has(PermissionFlags.Update))
{
    @*<i class="glyphicon glyphicon-edit" style="color: blue;"></i>*@
    <a href="@Url.Action("Edit", rv)" class="btn btn-primary btn-xs editcell">编辑</a>
}
else if (this.Has(PermissionFlags.Detail))
{
    @*<i class="glyphicon glyphicon-edit" style="color: blue;"></i>*@
    <a href="@Url.Action("Detail", rv)" class="btn btn-primary btn-xs editcell">查看</a>
}
@if (this.Has(PermissionFlags.Delete))
{
    var fact = ViewBag.Factory as IEntityFactory;
    var fi = (fact == null || fact.Fields == null) ? null : fact.Fields.FirstOrDefault(e => e.Name.EqualIgnoreCase("Deleted", "IsDelete", "IsDeleted"));
    if (fi != null && fi.Type == typeof(Boolean) && (Boolean)entity[fi.Name])
    {
        @*<i class="glyphicon glyphicon-transfer" style="color: green;"></i>*@
        <a href="@Url.Action("Delete", rv)" class="btn btn-danger btn-xs" data-action="action" data-confirm="确认恢复？">恢复</a>
    }
    else
    {
        @*<i class="glyphicon glyphicon-remove" style="color: red;"></i>*@
        <a href="@Url.Action("Delete", rv)" class="btn btn-danger btn-xs" data-action="action" data-confirm="确认删除？">删除</a>
    }
}